package com.example.myapplication.Ad;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.example.myapplication.R;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class pagerAd extends PagerAdapter {
    private Context mcontext;
    private int[] ints = {R.drawable.guide1,R.drawable.guide2,R.drawable.guide3};
    private List<View> list = new ArrayList<>();
    public pagerAd(Context mcontext){
        this.mcontext = mcontext;
        for (int i = 0; i < ints.length; i++) {
            View inflate = LayoutInflater.from(mcontext).inflate(R.layout.viewpager, null);
            ImageView imageView = inflate.findViewById(R.id.main2_imageView);
            imageView.setImageResource(ints[i]);
            list.add(inflate);
        }
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull @NotNull View view, @NonNull @NotNull Object object) {
        return view == object;
    }

    @NonNull
    @NotNull
    @Override
    public Object instantiateItem(@NonNull @NotNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
        container.removeView(list.get(position));
    }
}
